export default defineStore('user', {
  state: () => {
    return {
      user: {},
      token: '',
      form: {
        cookie: false,
        username: '',
        password: '',
      },
    }
  },
  actions: {
    setUser(user = {}) {
      this.user = user
    },
    setToken(token = '') {
      this.token = token
    },
    setForm(form) {
      this.form = {
        username: form?.username || '',
        password: form?.password || '',
        cookie: form?.cookie || false,
      }
    },
    logOut() {
      // 置空用户信息和token
      this.setUser()
      this.setToken()
    },
  },
  persist: true,
})
